package com.aigc.controller;


import com.aigc.domin.vo.MessageVO;
import com.aigc.service.ChatHistoryService;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ai/history")
public class HistoryController {
    @Autowired
    private ChatMemory chatMemory;
    @Autowired
    private ChatHistoryService chatHistoryService;
    @RequestMapping("/{type}")
    public List<String>  historyList(@PathVariable String type){
        return chatHistoryService.getChatHistory(null,type);
    }
    @RequestMapping("/{type}/{chatId}")
    public List<MessageVO>  history(@PathVariable String type, @PathVariable String chatId){
        List<Message> messages = chatMemory.get(chatId);
        return messages.stream().map(MessageVO::new).toList();
    }
}
